//
//  NSString+TextTranCode.m
//  DuoBaoKnigh
//
//  Created by aReu on 16/9/13.
//  Copyright © 2016年 aReu. All rights reserved.
//

#import "NSString+TextTranCode.h"

@implementation NSString(TextTranCode)

- (BOOL)isNUll {
    NSString *string = self;
    if (string == nil || string == NULL) {
        return YES;
    }
    if ([string isKindOfClass:[NSNull class]]) {
        return YES;
    }
    if ([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0) {
        return YES;
    }
    return NO;
}

+(NSMutableAttributedString*)needColor:(UIColor*)col
                                  size:(CGFloat)size
                             InContent:(NSString*)content{
    if (!col) {
        col = progBigBtnCol;
    }
    NSArray *number = @[@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"¥",@"%"];
    NSMutableAttributedString *attributeString  = [[NSMutableAttributedString alloc]initWithString:content];
    for (int i = 0; i < content.length; i ++) {
        NSString *a = [content substringWithRange:NSMakeRange(i, 1)];
        if ([number containsObject:a]) {
            [attributeString setAttributes:@{NSForegroundColorAttributeName:col,NSFontAttributeName:[UIFont systemFontOfSize:size],NSUnderlineStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleNone]} range:NSMakeRange(i, 1)];
        }
    }
    return attributeString;
}

+(NSString *)getMinuteSecondFrom:(NSTimeInterval)time
{
    int minute = (int)time / 60;
    int second = (int)time % 60;
    
    NSString *min;
    NSString *sec;
    
    if (minute < 10)
    {
        min = [NSString stringWithFormat:@"0%d",minute];
    }
    else
    {
        min = [NSString stringWithFormat:@"%d",minute];
    }
    
    if (second < 10)
    {
        sec = [NSString stringWithFormat:@"0%d",second];
    }
    else
    {
        sec = [NSString stringWithFormat:@"%d",second];
    }
    return [NSString stringWithFormat:@"%@:%@",min,sec];
}


@end
